/**
 * @Author: wangjian
 * 656876071@qq.com
 * @Date: 2024年8月8日 15:33:50
 * @LastEditTime: 2024-10-08 10:39:24
 * @FilePath: src/views/sys/api/SysMenuApi.ts
 * @Description:
 */
import r from '@/core/utils/request'

export interface SysMenu {
         menuId? : string;
         menuName? : string;
         parentId? : string;
         menuType? : string;
         component? : string;
         routeUrl? : string;
         params? : string;
         icon? : string;
         states? : string;
         visible? : string;
         orderNum? : string;
         delFlag? : string;
         remark? : string;
         createdBy? : string;
         createdTime? : string;
         updatedBy? : string;
         updatedTime? : string;

    [key:string]:any
}

export default () => {
    return {
        getPage: ({params: queryParams = {}, current = 1, size = 10}) => {
            return r.get('sys/menu/page', {
                params: {
                    current,
                    size,
                    ...queryParams
                }
            })
        }
        ,
        getById: (id: string) => {
            return r.get(`sys/menu/${id}`)
        },
        add:
            (rawObject: SysMenu) => {
                return r.post('sys/menu', rawObject)
            },
        update:
            (rawObject: SysMenu) => {
                return r.put(`sys/menu`, rawObject)
            }
            ,
        deleteById:
            (id: string) => {
                return r.delete(`sys/menu/${id}`)
            },
        copyMenuById:
            (id: string) => {
                return r.post(`sys/menu/copy/${id}`)
            }
    }
}

export interface SysMenuTree {
    menuId: string,
    menuName: string,
    parentId: string,
    menuType: string,
    component: string,
    routeUrl: string,
    params: string,
    icon: string,
    states: string,
    visible: string,
    orderNum: number,
    children?: SysMenuTree[]
}

export const useMenu = () =>{
    return {
        getMenuTree: () => r.get<SysMenuTree[]>('/v1/sys/menu/get-menu-tree'),
        getCatalogTree: () => r.get<SysMenuTree[]>('/v1/sys/menu/get-catalog-tree')
    }
}